import "../style/login.css";
import { EUV } from "@hongweifei/euv";
import { StatusCode } from "../api/web-result";
import { getUserInfo, login } from "../api/user";


new EUV({
    elementSelector: "#app",
    async mounted() {
        const userInfoResult = await getUserInfo();
        if (userInfoResult.code === StatusCode.SUCCESS) {
            alert("已登录");
            window.location.href = "../index.html";
        }
    },

    data: {
        formData: {
            username: "",
            password: ""
        }
    },

    methods: {
        gotoIndex() {
            window.location.href = "../index.html";
        },

        async submitLogin(e) {
            e.preventDefault();
            const { username, password } = this.data.formData;
            const result = await login({username, password});
            alert(result.message);
            if (result.code === StatusCode.SUCCESS) {
                window.location.href = "../index.html";
            }
        }
    }
});


